﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
#parse("common/head.html")
<link href="icon.ico" type="image/x-icon" rel="shortcut icon" />
<meta name="viewport" content="width=device-width"/>

<link rel="stylesheet" type="text/css" href="../css/style.css">
<link rel="stylesheet" type="text/css" href="../css/index.css">
<link rel="stylesheet" type="text/css" href="../css/h_index.css">
<link rel="stylesheet" type="text/css" href="../css/shop.css">
<!--[if IE 7]>
<link rel="stylesheet" href="/css/font-awesome/css/font-awesome-ie7.min.css">
<![endif]-->

<title>中建政研商学院</title>
</head>
<body align="center" style="padding:0;margin:0 auto;clear:both; align:center;">
#parse("common/header.html")
<div class="shop_nav">
    <a href="javascript:void(0);">
	<div class="shop_nav01"> 1.我的购物车 </div>
	<div class="shop_nav02"> </div>
	</a>
	<div class="shop_nav03"> </div>
	<div class="shop_nav04"> 2.确认订单信息 </div>
	<div class="shop_nav05"> </div>
	<div class="shop_nav03"> </div>
	<div class="shop_nav04"> 3.购买成功 </div>

</div>
<form id="confirm_cart" method="post" action="$!{form.domain}/cart/confirm">
<div class="shop_bodylist">
	<div class="shop_bodytitle"> 我的购物车 </div>
	<div class="shop_shopdiv">
		<div class="shop_shoptitle">
			<div class="shop_shoptitle01">
				<input type="checkbox" id="checkall" checked="checked"/>
				<label for="allcheck" style="margin-left:5px;">全选</label>
			</div>
			<div class="shop_shoptitle02">
				<div class="shop_shoptitle02"> 商品名称 </div>
			</div>
			<div class="shop_shoptitle03"> 价&nbsp;格 </div>
			<div class="shop_shoptitle03"> 操&nbsp;作 </div>
		</div>
        #foreach($data in $!form.cartList)
  		<div id="$velocityCount" class="shop_shopbody" >
  			<div class="shop_shopbody01">
  				<input name="idsList" type="checkbox" checked="checked" data="$!{data.curPrice}" value="$data.cartId" />
  			</div>
  			<div class="shop_shopbody03">
  				<div class="shop_shopbody03pic"> <a href="$!{form.domain}/course/detail/$!{data.courseId}"><img src="$!{form.getImageUrl($!{data.coursePimg})}" class="shop_listimg"/></a></div>
  				<div class="shop_shopbody03text">
  					<p><a href="$!{form.domain}/course/detail/$!{data.courseId}">$!{data.courseNm}</a> </p>
  					<p style="color:#666">讲师：$!{data.courseTeachernm} </p>
  				</div>
  			</div>
  			<div class="shop_shopbody04"> ¥$!{form.getPrice($!{data.curPrice})} </div>
  			<div class="shop_shopbody04"> <a href="javascript:delItem($velocityCount,'$data.cartId','$data.courseId', $!{data.curPrice})" style="color:#0A8CD2"> 删除 </a> </div>
  		</div>
        #end
		<div class="shop_shoptitle" style="border-bottom:none;border-top:none;height:90px; ">
			<div class="shop_shoptitle01" style="width:auto;">
				<input type="checkbox" id="learn_credit" name="useState" value="true"/>
				<label for="studym" style="margin-left:5px;">使用学习币</label>
				<span style="color:#666">（余额：¥$!{form.getPrice($!{form.coin2Fen})}）</span>
			</div>
			<div class="shop_shoptitle03" style="width:180px;text-align:left;float:right;margin-right:40px;">
				<p>总计：<span id="all_course_price" style="float:right;"> ¥$!{form.getPrice($!{form.count})} </span> </p>
				<p>优惠：<span id="discount_amount" style="float:right;"> －¥$!{form.getPrice($!{form.discountAmount})} </span> </p>
				<p>学习币支付：<span id="sub_learn_credit" style="float:right;">－¥0 </span> </p>
			</div>
		</div>
		<div class="shop_shoptitle" style="border-bottom:none;border-top:none;height:40px;background-color:#EFEFEF ">
			<div class="shop_shoptitle01" style="width:auto;">
			</div>
			<div class="shop_shoptitle02" style="width:530px;line-height:40px;"> 已选课程
			<span id="select_course_count" style="font-size:14px;color:#FF6600"> $!form.cartList.size()</span> 门</div>
			<div class="shop_shoptitle03" style="width:170px;text-align:left;line-height:40px;">
				<p>总合计：<span id="total_money" style="float:right;font-size:16px;color:#FF6600"> ¥$!{form.getPrice($!{form.amount})} </span> </p>
			</div>
			<a href="javascript:orderConfirm();"> <div class="shop_shopbodycount"> 去结算</div> </a> 
		</div>
	</div>
</div>
</form>
#parse("common/footer.html")
<script type="text/javascript">
$(document).ready(function(){
	//全选、取消全选
	$("#checkall").click(function() {
        var flag = $(this).attr("checked");
        $("[name='idsList']:checkbox").each(function() {
            $(this).attr("checked", flag); 
        });
        
        setData();
    }); 
	
    var subcheck = $("[name='idsList']:checkbox"); 
    var check = $("#checkall"); 
    subcheck.click(function(){ 
        var flag = true; 
        subcheck.each(function(){ 
            if(!this.checked){
            	flag = false; 
            }
        }); 
        check.attr("checked",flag); 
        
        setData();
    });

    //选择学习币事件
    $("#learn_credit").change(function() {
    	var allCoursePrice = getAllCoursePrice();
    	var learnCredit = $!{form.coin2Fen};
    	var discountAmount = getDiscountPrice();
    	
        if (!$("#learn_credit").attr("checked")) {
        	$("#sub_learn_credit").html("－¥0");
        }else if($("#learn_credit").attr("checked")){
        	if((allCoursePrice - discountAmount)>learnCredit){
      			$("#sub_learn_credit").html("－¥$!{form.getPrice($!{form.coin2Fen})}");
      		}else{
      			$("#sub_learn_credit").html("－¥" + Math.round(parseFloat(allCoursePrice - discountAmount))/100);
      		}
        }
      	$("#total_money").html("¥" + Math.round(parseFloat(getAmount()))/100);
    });
    
})

var delItem=function(divId, cartId, courseId, price){
  if(confirm("确定要删除此课程？")){
  	var _url="/cart/del/"+cartId+"/"+courseId;
  	jQuery.ajax({
  		type: "GET",
  		url: _url,
  		cache:false,
  		async:false,
  		dataType: "json",
  		success: function(data){
  			if (data.status != '200') {
  				alert(data.status)
  			}else{
  				$("#"+ divId).remove();
  				setData();
  			}
  		}
  	})
  }
}

var getAllCoursePrice = function(){
	var amount = 0;
	$("[name='idsList']:checkbox").each(function() {
		if(this.checked){
			amount += parseInt($(this).attr("data"));
		}
    });
	return amount;
}

var getAmount = function(){
	var amount = 0;
	var allCoursePrice = getAllCoursePrice();
	var learnCredit = $!{form.coin2Fen};
	var discountAmount = getDiscountPrice();
	var lcFlag = $("#learn_credit").attr("checked");
	if(lcFlag){
		if((allCoursePrice - discountAmount)>learnCredit){
			amount = allCoursePrice - discountAmount - learnCredit;
		}else{
			amount = 0;
		}
	}else{
		amount = allCoursePrice - discountAmount;
	}
	return amount;
}
//课程数
var getCourseSize = function(){
	var size = 0;
	$("[name='idsList']:checkbox").each(function() {
		if(this.checked){
			size += 1;
		}
    });
	return size;
}
//优惠金额
var getDiscountPrice = function(){
	//var tp = $!{form.promotion.promotionTp};
	//var promotionMoney = $!{form.promotion.promotionMoney};
	//have no promotion
	var tp = -1;
	#if($form.promotion.promotionTp )  
		tp =$!{form.promotion.promotionTp};
	#end
	var promotionMoney = 0;
	#if($form.promotion.promotionMoney )
		promotionMoney= $!{form.promotion.promotionMoney};
	#end

	
	
	
	var allCoursePrice = getAllCoursePrice();
	if(tp == 1){
		if(allCoursePrice > promotionMoney){
			return $!{form.promotion.reduceMoney};
		}else{
			return 0;
		}
	}else if(tp == 2){
		if(allCoursePrice > promotionMoney){
			return allCoursePrice * parseDouble($!{form.promotion.reduceMoney});
		}else{
			return 0;
		}
	}else{
		return 0;
	}
}
var setData = function(){
	$("#all_course_price").html("¥" + Math.round(parseFloat(getAllCoursePrice()))/100);
  	$("#total_money").html("¥" + Math.round(parseFloat(getAmount()))/100);
  	$("#discount_amount").html("－¥" + Math.round(parseFloat(getDiscountPrice()))/100);
  	$("#select_course_count").html(getCourseSize());
}

var orderConfirm = function(){
	$("[name='idsList']:checkbox").each(function() {
		if(this.checked){
			$('#confirm_cart').submit();
		}
    });
}
</script>
</body>
</html>